function Queue(size = 100) {
    this.init(size)
}

// 初始化空队列
Queue.prototype.init = function (size) {
    this.size = size + 1
    this.queue = new Array(size + 1).fill(null)
    this.front = 0
    this.rear = 0
}
// 判断队列是否为空
Queue.prototype.isEmpty = function () {
    return this.front === this.rear
}
// 判断队列是否已满
Queue.prototype.isFull = function () {
    return (this.rear + 1) % this.size === this.front
}
// 入队操作
Queue.prototype.enqueue = function (value) {
    if (this.isFull()) {
        throw new Error('Queue is full')
    } else {
        this.rear = (this.rear + 1) % this.size
        this.queue[this.rear] = value
    }
}
// 出队操作
Queue.prototype.dequeue = function () {
    if (this.isEmpty()) {
        throw new Error('Queue is empty')
    } else {
        this.queue[this.front] = null
        this.front = (this.front + 1) % this.size
        return this.queue[this.front]
    }
}
// 获取队头元素
Queue.prototype.frontValue = function () {
    if (this.isEmpty()) {
        throw new Error('Queue is empty')
    } else {
        return this.queue[(this.front + 1) % this.size]
    }
}
// 获取队尾元素
Queue.prototype.rearValue = function () {
    if (this.isEmpty()) {
        throw new Error('Queue is empty')
    } else {
        return this.queue[this.rear]
    }
}
let queue = new Queue(3)
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(3)
queue.dequeue()
console.log(queue.frontValue())
console.log(queue.rearValue())